<%@page import="cn.yunhe.util.PageController"%>
<%@page import="cn.yunhe.entity.News"%>
<%@page import="cn.yunhe.biz.NewsBiz"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'newsList.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<style>
	td{
		text-align: center;
	}
</style>
  </head>
	<%
		//获得当前的页数
		String pageIndex=request.getParameter("pageIndex");
		//如果是首页(没有页码)
		if(pageIndex==null){
			pageIndex="1";
		}
		
		//将当前页转换为整型
		int currentPage=Integer.parseInt(pageIndex);
		//每页显示的条数
		int pageSize=3;
		
		NewsBiz newsBiz=new NewsBiz();
		//得到总条数
		int count=newsBiz.getNewsCount();
	    PageController pc=new PageController();
	  	//根据总条数和每页显示的条数得到总页数
	    int totalPages=pc.getTotalPage(count, pageSize);
	  	
	  	//如果首页点上一页
	  	if(currentPage<1){
	  		currentPage=1;
	  	}else if(currentPage>totalPages){
	  		currentPage=totalPages;
	  	}
	  	
		
	  	List<News> list=newsBiz.getNewsByPage(pageSize, currentPage);
		
	%>  
  <body background="pic/ManBgroud.gif">
  	  <a href="admin/addNews.jsp">新增新闻</a>
  	  <table style="width: 80%; border: 1px solid #006666">
			<tr>
				<th>编号</th>
				<th>标题</th>
				<th>发布人儿</th>
				<th>发布时间</th>
				<th>类别</th>
				<th>操作</th>
			</tr>
			<%
				for(int i=0;i<list.size();i++){
					News news=list.get(i);
			%>
			
			<tr>
				<td><%=news.getNewsId() %></td>
				<td><%=news.getNewsTitle() %></td>
				<td><%=news.getAdmin().getAdminId() %></td>
				<td><%=news.getNewsPtime() %></td>
				<td><%=news.getCate().getCateId() %></td>
				<td><a href="">编辑</a>|<a href="">删除</a></td>
			</tr>
			<%} %>  
			
			<tr>
				<td colspan="6" align="center">
					<a href="admin/newsList.jsp?pageIndex=1">首页</a>
					<a href="admin/newsList.jsp?pageIndex=<%=currentPage-1%>">上一页</a>
					<a href="admin/newsList.jsp?pageIndex=<%=currentPage+1%>">下一页</a>
					<a href="admin/newsList.jsp?pageIndex=<%=totalPages%>">尾页</a>
				</td>
			</tr>	  
  	  
  	  </table>
  	  
  	  
  </body>
</html>
